import { createRouter, createWebHistory } from 'vue-router'
// import Params from '../views/'
import store from '../store'
const routes = [
  {
    path:'/',
    redirect:'/index'
  },
  {
    path:'/login',
    name:'login',
    component: import(/* webpackChunkName: "login" */ '../views/Login/Login.vue')
  },
  {
    path: '/index',
    name: 'index',
    component: () => import(/* webpackChunkName: "index" */ '../views/Index/Index.vue'),
    redirect:'/index/users',
    children:[
      {
        path:'users',
        name:'users',
        component:() => import(/* webpackChunkName: "users" */ '../views/Users/Users.vue')
      },
      {
        path:'roles',
        name:'roles',
        component:() => import(/* webpackChunkName: "roles" */ '../views/Roles/Roles.vue')
      },
      {
        path:'rights',
        name:'rights',
        component:() => import(/* webpackChunkName: "rights" */ '../views/Rights/Rights.vue')
      },
      {
        path:'goods',
        name:'goods',
        component:() => import(/* webpackChunkName: "goods" */ '../views/Goods/Goods.vue'),
      },
      {
        path:'add',
        name:'add',
        component: () => import(/* webpackChunkName: "goods" */ '../views/Goods/Add.vue')
      },
      {
        path:'categories',
        name:'categories', 
        component:() => import(/* webpackChunkName: "categories" */ '../views/Categories/Categories.vue')
      },
      {
        path:'orders',
        name:'orders',
        component:() => import(/* webpackChunkName: "orders" */ '../views/Orders/Orders.vue')
      },
      {
        path:'params',
        name:'params',
        component:() => import(/* webpackChunkName: "params" */ '../views/Params/Params.vue')
      },
      {
        path:'reports',
        name:'reports',
        component:() => import(/* webpackChunkName: "reports" */ '../views/Reports/Reports.vue')
      },

    ]
  },
  
]

const router = createRouter({
  history: createWebHistory(),
            
  routes
})

router.beforeEach((to,from,next)=>{
  if(!store.state.token && to.name!='login'){
    next('/login')
    return ;
  }
  next()
})
export default router
